<?php

/**
 * 当前位置
 *
 * @package    01CMS
 * @subpackage plugin
 * @author     rolong at vip.qq.com
 * @version    1.0.0
 * @link       http://www.01cms.com
 */

function smarty_function_categoryPosition ($params)
{
    if (! isset($params['isLink']))
    {
        $params['isLink'] = 1;
    }
    
    if (! isset($params['sign']))
    {
        $params['sign'] = ' » ';
    }
    
    $Category = model('Category');
    $Category->getParent($params['id']);
    $parent = $Category->parentCategory;
    $string = '';
    
    foreach ($parent as $o)
    {
        if ($params['isLink'])
        {
            $o->activeUrl = BOOT_URL . '/data/category/' . $o->id;
            $o->staticUrl = ROOT_DIR . Base::i()->Load->var['htmlSaveDir'] . '/' . $o->alias;
            switch ($o->visit)
            {
                case 1:
                {
                    $o->url = $o->staticUrl;
                }
                case 2:
                {
                    $o->url = $o->activeUrl;
                }
                default:
                {
                    $o->url = defined('staticHtml') ? $o->staticUrl : $o->activeUrl;
                }
            }
            
            $o->name = "<a href=\"{$o->url}\">{$o->name}</a>";
        }
        
        if (empty($string))
        {
            $string = $o->name;
        }
        else
        {
            $string = $o->name . $params['sign'] . $string;
        }
    }
    
    return $string;
}
